#!/usr/bin/env python
#-*- coding:utf-8 -*-

import os
import sys
import string
import thread
import threading
import time

def doCmd(filename):
    global count, mutex

    mutex.acquire()
    count += 1
    mutex.release()

    cmd = "/root/wanalytics/scripts/multithread/up.sh %s" % filename
    os.system(cmd)

    mutex.acquire()
    count -= 1
    mutex.release()

    thread.exit_thread()

def main():
    global count, mutex

    count = 0
    mutex = threading.Lock()

    thread.start_new_thread(doCmd, ("aa",))
    thread.start_new_thread(doCmd, ("ab",))
    thread.start_new_thread(doCmd, ("ac",))
    thread.start_new_thread(doCmd, ("ad",))
    thread.start_new_thread(doCmd, ("ae",))
    thread.start_new_thread(doCmd, ("af",))
    thread.start_new_thread(doCmd, ("ag",))
    thread.start_new_thread(doCmd, ("ah",))

    time.sleep(60)
    while True:
        if count != 0:
            print "count = %d" % count
            time.sleep(20)
        else:
            break

if __name__ == '__main__':
    main()

